package com.me.study.arithmeticAndDataStructure.backoff;

import org.springframework.util.backoff.BackOff;
import org.springframework.util.backoff.BackOffExecution;
import org.springframework.util.backoff.ExponentialBackOff;
import org.springframework.util.backoff.FixedBackOff;

/**
 * Spring 的固定间隔退避算法工具类
 *
 * @author ME
 * @date 2021/9/27
 */
public class TestFixedBackOff {

    public static void main(String[] args) {
        //重试间隔
        long interval = 1000;
        //最大重试次数
        long maxAttempts = 10;
        BackOff backOff = new FixedBackOff(interval, maxAttempts);
        BackOffExecution execution = backOff.start();

        while(true){
            long value = execution.nextBackOff();
            System.out.println(value);
            if(value == BackOffExecution.STOP){
                break;
            }
        }
    }

}
